import store from '@/store/index.js'

module.exports = {
	data() {
		return {
			baiduTokenParams: {
				grant_type: 'client_credentials',
				client_id: 'UIt5pWxytL5SE9Xe9BoE0Txm',
				client_secret: 'mqFeIaWgUtz83UnLFU0VnnQYlyFz7Ljn'
			}
		}
	},
	methods: {
		// 获取当前登录用户的基本信息
		postGetUserInfo() {
			let that = this
			// uni.getUserInfo({
			// 	provider: 'weixin',
			// 	success: function(infoRes) {
			// 		that.userInfo = infoRes.userInfo
			// 		uni.setStorageSync('avatarUrl', infoRes.userInfo.avatarUrl);
			// 	}
			// });
			uni.setStorageSync('nickName', '小鲸洗用户');
		},
		// 获取openId
		login() {
			let that = this
			return new Promise((resolve, reject) => {
				uni.login({
					provider: 'kuaishou',
					onlyAuthorize: true,
					success: (res) => {
						this.$u.api.postGetKsOpenId({
							code: res.code
						}).then(res => {
							uni.setStorageSync('userInfo', res.data)
							store.commit('setUserInfo', res.data)
							resolve(res)
						})
						// this.$u.api.getBaiduToken(this.baiduTokenParams).then(res => {
						// 	store.commit('setBaiduInfo', res)
						// })
					}
				})
			})

		},
		//通过openId获取token
		// getTokenByOpenId(openId) {
		// 	let that = this
		// 	that.$u.api
		// 		.postLoginCheck({
		// 			openId
		// 		})
		// 		.then(res => {
		// 			uni.setStorageSync('token', res.data.token);

		// 			this.postGetUserInfo()
		// 		})
		// },
	},
}